<?php

namespace app\common;

class BaseHelper
{

    /**
     * curl POST方式实现
     * @param $url
     * @param $postData
     * @return mixed
     * @author fei <xliang.fei@gmail.com>
     */
    public static function curlPost($url, $postData)
    {
        //初始化
        $curl = curl_init(); //用curl发送数据给api
        curl_setopt($curl, CURLOPT_POST, true);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        $response = curl_exec($curl);
        //关闭URL请求
        curl_close($curl);
        //显示获得的数据
        return $response;
    }

    /**
     * curl GET方式实现
     * @param $url
     * @return mixed
     * @author fei <xliang.fei@gmail.com>
     */
    public static function curlGet($url)
    {
        //初始化
        $curl = curl_init();
        //设置抓取的url
        curl_setopt($curl, CURLOPT_URL, $url);
        //设置获取的信息以文件流的形式返回，而不是直接输出。
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        //执行命令
        $data = curl_exec($curl);
        //关闭URL请求
        curl_close($curl);
        //显示获得的数据
        return $data;
    }
    //生成唯一ID
    public static function getUUID($prefix=''){
        $uuid = md5(uniqid(mt_rand(), true));
        return $prefix . $uuid;
    }

    public static function getUUID22(){
        $uuid = md5(uniqid(mt_rand(), true));
        return substr($uuid,mt_rand(0,10),22);
    }

    //加密算法
    public static function password_hash($pwd){
        $options = [
            'cost' => 12,
        ];
        $password = password_hash($pwd,PASSWORD_DEFAULT,$options);
        return $password;
    }
}